!function () {

	layui.config({base: '/layui/lay/modules/'}).use(['table', 'laydate', 'dateformat', 'form'], function () {
		var $ = layui.jquery, table = layui.table, dateformat = layui.dateformat, form = layui.form,
			laydate = layui.laydate;


        //自定义验证规则
		form.verify({
			pass:[/^[0-9A-Za-z]{8,16}$/,'密码必须8到16位，数字和字母的组合，支持纯数字和纯字母']
		});
		//提交
		form.on('submit(editUser)', function (data) {
			if( data.field.newPass != data.field.newPass1 ){
                layer.msg('温馨提示：两次输入的新密码不一致', {time: 5000, icon:6});
                return false;
			}

			$.ajax({
				async: false, type: 'post', traditional: true, data: data.field, url: '/user/changePass',
				success: function (data) {
					if (data && data.code == 200) {
						layer.alert('操作成功！', {icon: 1, title: '提示',yes: function(){
                                location.href = '/login';
							}});
					} else
						layer.alert(data.msg || '操作失败了！', {icon: 5, title: '提示'});
				},
				error: function (data) {
					if( data.responseJSON.message ){
                        layer.alert(data.responseJSON.message, {icon: 2, title: '错误'});
					}else{
                        layer.alert('服务器出错啦！', {icon: 2, title: '错误'});
					}
				}
			});
			return false;
		});
	});
}();
